<template>
  <div>
    <a-form
    layout="inline"
    :model="formState"
  >
    <a-form-item>
      <a-input v-model:value="formState.formname" placeholder="FormName">
        <template #prefix><UserOutlined style="color: rgba(0, 0, 0, 0.25)" /></template>
      </a-input>
    </a-form-item>
    <a-form-item>
      <a-button
        type="primary"
        html-type="submit"
        :disabled="formState.formname === ''"
        @click="sendData()"
        
      >
       Select
      </a-button>
    </a-form-item>
  
  </a-form>
  </div>
  <div>
      <RouterView></RouterView>
  </div>
</template>
<script lang="ts" setup>
import { computed, reactive,ref } from 'vue';
import axios from 'axios';
import {useCounterStore} from '@/stores/counter'
import { useRouter } from "vue-router";
const $router = useRouter();
let address='/MenuTable'
const store=useCounterStore()
   const formState = reactive({
           formname: '',
     });
type Key = string | number;

interface DataType {
  key: Key;
  formName: string;
  ID: number;
  Data: string;
}
let data: DataType[] = [];
function sendData(){
  axios.post('http://127.0.0.1:8080/userData/select', {
            formName: formState.formname,
        }).then(response => {
           if(response.data!=null){
                data=[]
                for(let i=0;i<response.data.length;i++){
                  data.push(
                    {
                      key: response.data[i].dataId,
                      formName: response.data[i].formName,
                      ID: response.data[i].dataId,
                      Data: response.data[i].formData
                    }
                  )
                
            }
           
            store.change(JSON.stringify(data))
            if(address=="/MenuTable"){
                 address="/MenuTable1"
            }else
               address="/MenuTable"
            showRouter()
          }
       
           
        })
}
function showRouter(){
  $router.push({
         path: address, // 目标路由路径
         // 可选：传递查询参数
  });
}
</script>

